

/* Create Sequences */

CREATE SEQUENCE SEQ_admin_id INCREMENT BY 1 START WITH 1;
CREATE SEQUENCE SEQ_admin_role_id INCREMENT BY 1 START WITH 1;
CREATE SEQUENCE SEQ_role_id INCREMENT BY 1 START WITH 1;
CREATE SEQUENCE SEQ_role_name_role_id INCREMENT BY 1 START WITH 1;
CREATE SEQUENCE SEQ_ti_admin_admin_id INCREMENT BY 1 START WITH 1;
CREATE SEQUENCE SEQ_ti_role_role_id INCREMENT BY 1 START WITH 1;
CREATE SEQUENCE SEQ_ti_standby_id INCREMENT BY 1 START WITH 1;
CREATE SEQUENCE SEQ_ti_user_user_id INCREMENT BY 1 START WITH 1;
CREATE SEQUENCE SEQ_uri_name_uri_id INCREMENT BY 1 START WITH 1;
CREATE SEQUENCE SEQ_user_id INCREMENT BY 1 START WITH 1;



/* Create Tables */

CREATE TABLE admin_role
(
	id number NOT NULL,
	admin_name varchar2(255 char),
	admin_role varchar2(255 char),
	PRIMARY KEY (id)
);


CREATE TABLE role_name
(
	-- 
	-- 
	role_id number NOT NULL,
	-- 角色名称
	-- 
	role_name varchar2(255 char),
	PRIMARY KEY (role_id)
);


CREATE TABLE ti_admin
(
	adminName varchar2(255 char) NOT NULL UNIQUE,
	admin_id number NOT NULL,
	password varchar2(255 char) NOT NULL,
	PRIMARY KEY (admin_id)
);


CREATE TABLE ti_order
(
	order_id varchar2(255) NOT NULL,
	train_number number NOT NULL,
	start_date date NOT NULL,
	end_date date NOT NULL,
	start_location varchar2(255 char) NOT NULL,
	end_location varchar2(255 char) NOT NULL,
	username varchar2(255) NOT NULL,
	status varchar2(255) NOT NULL,
	type number NOT NULL,
	PRIMARY KEY (order_id)
);


CREATE TABLE ti_role
(
	role_id number NOT NULL,
	role varchar2(255 char),
	uri varchar2(255 char),
	PRIMARY KEY (role_id)
);


CREATE TABLE ti_standby
(
	id number NOT NULL,
	start_location varchar2(255 char) UNIQUE,
	end_location varchar2(255 char),
	start_time date,
	end_time date,
	num number,
	start_day date,
	price number,
	type number,
	PRIMARY KEY (id)
);


CREATE TABLE ti_user
(
	user_name varchar2(255 char) NOT NULL UNIQUE,
	password varchar2(255 char) NOT NULL,
	idCard varchar2(255 char) UNIQUE,
	gender number,
	register_date date,
	user_id number NOT NULL,
	type number,
	PRIMARY KEY (user_id)
);


CREATE TABLE uri_name
(
	uri_id number NOT NULL,
	uri varchar2(255 char),
	PRIMARY KEY (uri_id)
);



/* Create Triggers */

CREATE OR REPLACE TRIGGER TRI_admin_id BEFORE INSERT ON admin
FOR EACH ROW
BEGIN
	SELECT SEQ_admin_id.nextval
	INTO :new.id
	FROM dual;
END;

/

CREATE OR REPLACE TRIGGER TRI_admin_role_id BEFORE INSERT ON admin_role
FOR EACH ROW
BEGIN
	SELECT SEQ_admin_role_id.nextval
	INTO :new.id
	FROM dual;
END;

/

CREATE OR REPLACE TRIGGER TRI_role_id BEFORE INSERT ON role
FOR EACH ROW
BEGIN
	SELECT SEQ_role_id.nextval
	INTO :new.id
	FROM dual;
END;

/

CREATE OR REPLACE TRIGGER TRI_role_name_role_id BEFORE INSERT ON role_name
FOR EACH ROW
BEGIN
	SELECT SEQ_role_name_role_id.nextval
	INTO :new.role_id
	FROM dual;
END;

/

CREATE OR REPLACE TRIGGER TRI_ti_admin_admin_id BEFORE INSERT ON ti_admin
FOR EACH ROW
BEGIN
	SELECT SEQ_ti_admin_admin_id.nextval
	INTO :new.admin_id
	FROM dual;
END;

/

CREATE OR REPLACE TRIGGER TRI_ti_role_role_id BEFORE INSERT ON ti_role
FOR EACH ROW
BEGIN
	SELECT SEQ_ti_role_role_id.nextval
	INTO :new.role_id
	FROM dual;
END;

/

CREATE OR REPLACE TRIGGER TRI_ti_standby_id BEFORE INSERT ON ti_standby
FOR EACH ROW
BEGIN
	SELECT SEQ_ti_standby_id.nextval
	INTO :new.id
	FROM dual;
END;

/

CREATE OR REPLACE TRIGGER TRI_ti_user_user_id BEFORE INSERT ON ti_user
FOR EACH ROW
BEGIN
	SELECT SEQ_ti_user_user_id.nextval
	INTO :new.user_id
	FROM dual;
END;

/

CREATE OR REPLACE TRIGGER TRI_uri_name_uri_id BEFORE INSERT ON uri_name
FOR EACH ROW
BEGIN
	SELECT SEQ_uri_name_uri_id.nextval
	INTO :new.uri_id
	FROM dual;
END;

/

CREATE OR REPLACE TRIGGER TRI_user_id BEFORE INSERT ON user
FOR EACH ROW
BEGIN
	SELECT SEQ_user_id.nextval
	INTO :new.id
	FROM dual;
END;

/




/* Comments */

COMMENT ON COLUMN role_name.role_id IS '
';
COMMENT ON COLUMN role_name.role_name IS '角色名称
';



